# Contributor: Carlo Landmeter <clandmeter@alpinelinux.org>
# Contributor: Patrycja Rosa <alpine@ptrcnull.me>
# Maintainer: leso-kn <info@lesosoftware.com>
pkgname=woodpecker
pkgver=2.0.0
pkgrel=0
pkgdesc="Woodpecker is a community fork of the Drone CI system."
url="https://woodpecker-ci.org"
# s390x, riscv64: currently not supported by esbuild
arch="all !s390x !riscv64"
license="Apache-2.0"
pkgusers="woodpecker"
pkggroups="woodpecker"
makedepends="
	go
	go-swag
	pnpm
	sqlite-dev
	"
subpackages="$pkgname-doc $pkgname-openrc"
install="$pkgname.pre-install"
source="$pkgname-$pkgver.tar.gz::https://github.com/woodpecker-ci/woodpecker/archive/refs/tags/v$pkgver.tar.gz
	no-ext-static.patch
	use-rollup-wasm.patch
	woodpecker.initd
	woodpecker.confd
	woodpecker.conf
	"

export GOFLAGS="$GOFLAGS -tags=libsqlite3"
export GOCACHE="${GOCACHE:-"$srcdir/go-cache"}"
export GOTMPDIR="${GOTMPDIR:-"$srcdir"}"
export GOMODCACHE="${GOMODCACHE:-"$srcdir/go"}"

build() {
	export TARGETARCH="$(go env GOHOSTARCH)"
	make build
}

check() {
	go test ./...
}

package() {
	install -Dm755 "$builddir"/dist/woodpecker-server \
		"$pkgdir"/usr/bin/woodpecker-server
	install -Dm755 "$builddir"/dist/woodpecker-agent \
		"$pkgdir"/usr/bin/woodpecker-agent
	install -Dm755 "$builddir"/dist/woodpecker-cli \
		"$pkgdir"/usr/bin/woodpecker-cli
	install -Dm 644 "$builddir"/LICENSE \
		"$pkgdir"/usr/share/licenses/$pkgname/LICENSE

	install -Dm755 "$srcdir"/woodpecker.initd \
		"$pkgdir"/etc/init.d/woodpecker
	install -Dm644 "$srcdir"/woodpecker.confd \
		"$pkgdir"/etc/conf.d/woodpecker

	install -Dm640 -o woodpecker -g woodpecker "$srcdir"/woodpecker.conf \
		"$pkgdir"/etc/woodpecker.conf
	install -dm755 -o woodpecker -g woodpecker "$pkgdir"/var/lib/woodpecker
}

sha512sums="
6fa15c547b435cc9cc24dc65ebd78a7d7d15a952e4cc35c258a1b161af66a331c0e63a451f6c80da1b1d9d86dfe4c59f26ea1cb4d3a4699cec73413a7c29ee0a  woodpecker-2.0.0.tar.gz
51d9a1ed3051ff806ae200cd5ef21c546498d255ad3741997426f761055caa2a50ad1799b09c945ede249cb035e9d68936c9fcff7ea0fa70ffa541af9acd6307  no-ext-static.patch
ab865c97117c5afffc781c27f021e7eb09d6029f901d35fd5a2b5e039ea2397ffeeac0ae4090c97f23b07d47e736363068a823577f4455297742254e8ca701e9  use-rollup-wasm.patch
69fe477f805dcb71b0220b9af2b3d0226b2e92f3c46764f37a139bb7303ad7cdb1caa2a711d1f9d22fccb357bbfbecb1c6cba2033c9101a11c0bb67b405c3e55  woodpecker.initd
0be91432e730cb0ad3663bebe7a257437cbefe5fa5c2f3145d621545d6cd2ff89ae41f338a5874166d2b03dc8caab73d26cd4322ed1122d4949cae5d6002b823  woodpecker.confd
cb15d7ff290d9b68d5f63c20401ab622c8a7067d336841c876a6d3325e9d2a3ede3a85b792131d7d77a4126cbdb6f30a5a6113468f1efd736a2c1bbf2bfefbe4  woodpecker.conf
"
